package com.cheung.leetcode.day;

import  org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.day
 * @Author :  cheungming
 * @CreateTime : 2024-07-05 15:44:01
 * @Description : 每日 一题
 * @Version : 1.0
 */
public class Code3033Test {
    public int[][] modifiedMatrix(int[][] matrix) {
        for (int j = 0; j < matrix[0].length; j++) {
            // 找到每一列的最大值
            int max = -1;
            for (int[] its : matrix) {
                max = Math.max(max, its[j]);
            }

            // 将-1的位置替换成最大值
            for (int i = 0; i < matrix.length; i++) {
                if (matrix[i][j] == -1) {
                    matrix[i][j] = max;
                }
            }
        }
        return matrix;
    }

    @Test
    public void test1() {
        int[][] matrix = {{1, 2, -1}, {4, -1, 6}, {7, 8, 9}};
        int[][] res = {{1, 2, 9}, {4, 8, 6}, {7, 8, 9}};
        assert Arrays.deepEquals(modifiedMatrix(matrix), res);
    }
}
